<?php
/**
 * Created by PhpStorm.
 * User: shaowei
 * Date: 2019/5/1
 * Time: 下午2:27
 */

namespace App\Console\Commands;
use App\Http\Model\CoolNumberShoppingMall\CoolNumber;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;


class GeneratedUid extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'generateduid';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '生成用户注册UID（执行一次，切勿执行第二次）';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $index = Redis::GET("USER:UID:GENERATED:INDEX");

        if (empty($index)){
            $index = 120000;
        }
        $index = $index + 1;
        $model = new CoolNumber();
        for ($i = $index; $i < $index + 300000; $i++){
            Redis::SET("USER:UID:GENERATED:INDEX", $i);
            if ($model->getCoolNumberType($i)){
                continue;
            }
            Redis::RPUSH("USER:UID:GENERATED:DB", $i);
        }
    }
}
